20. Encapsulation in C++

Encapsulation Definition

In the context of object oriented programming, encapsulation refers to:

SOLUTION: The notion that data and logic can be packaged together and passed around within a program as a single object.

Keyword const

Invoking the const keyword in an accessor function allows you to:

SOLUTION: Ensure the user cannot do anything to change the private attributes of the object.

Setter function

Making class attributes private and assigning them with a mutator function allows you to:

SOLUTION: Invoke logic that checks whether the input data are valid before setting attributes.